package com.fancy.mobileschool.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fancy.mobileschool.R;
import com.fancy.mobileschool.entity.Course;
import com.fancy.mobileschool.ui.YunFileActivity;
import com.fancy.mobileschool.ui.adapt.CouseShareDirListAdapt;
import com.fancy.mobileschool.ui.widget.DividerItemDecoration;

import java.util.List;

/**
 * Created by Jackie on 2017/11/14.
 */

public class CourseShareFileFragment extends Fragment {

    private RecyclerView recyclerView;

    private YunFileActivity yunFileActivity;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        yunFileActivity = (YunFileActivity) getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_course_share_dir_list, container, false);
        // Set the adapter
        if (view instanceof RecyclerView) {
            Context context = view.getContext();
            recyclerView = (RecyclerView) view;
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
        }

        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        yunFileActivity.getShareCourse();
    }

    public void setAdapter(List<Course> courses) {
        recyclerView.setAdapter(new CouseShareDirListAdapt(courses, getActivity()));
    }
}
